package cn.wolfcode.controller;

import cn.wolfcode.domain.StrategyTheme;
import cn.wolfcode.query.StrategyThemeQuery;
import cn.wolfcode.repository.StrategyThemeRepository;
import cn.wolfcode.service.IDestinationService;
import cn.wolfcode.service.IStrategyThemeService;
import cn.wolfcode.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("strategyTheme")
public class StrategyThemeController {
    @Autowired
    private IStrategyThemeService strategyThemeService;

    @RequestMapping("list")
    public Object list(Model model,StrategyThemeQuery qo){
        Page query = strategyThemeService.query(qo);
        model.addAttribute("qo",qo);
        model.addAttribute("page",query);

        return "/strategyTheme/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyTheme strategyTheme){
        if (!(strategyTheme.getId() == null)){
            strategyThemeService.update(strategyTheme);
        }else {
            strategyThemeService.insert(strategyTheme);
        }
        return JsonResult.success();
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(String id){
        if (id != null){
            strategyThemeService.delete(id);
            return JsonResult.success();
        }
        return JsonResult.defaultError();
    }
}
